/**
 * use Element-Plus (ElMessage)
 */
export default {
  mounted(el,{value}){
    el.$value = value
    el.handler = () => {
      const { text,message } = el.$value
      const textDom = document.createElement('input')
      textDom.readOnly = 'readonly'
      textDom.value = text
      document.body.appendChild(textDom)
      console.log(textDom)
      textDom.select()
      textDom.setSelectionRange(0, textDom.value.length)
      const result = document.execCommand('Copy')
      if (result) {
        ElMessage.success(message || '复制成功')
      }
      document.body.removeChild(textDom);
    }
    el.addEventListener('click', el.handler)
  },
  updated(el, { value }) {
    el.$value = value
  },
  unmounted(el) {
    el.removeEventListener('click', el.handler)
  }
}